package com.adhere.auth.remote.fallback;

import com.adhere.auth.pojo.LoginUser;
import com.adhere.auth.remote.RemoteUserService;
import com.adhere.common.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 *
 * @author WT
 * @date 2022/02/08 08:54:57
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService() {

            @Override
            public Result<LoginUser> getUserByLoginName(String loginName) {
                return Result.error("获取用户失败:" + throwable.getMessage());
            }

        };
    }
}
